<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>BMI指数</title>
	</head>
	<body>
		<p>请输入身高(cm)：</p>
		<input type="text" id="height" />
		<p>请输入体重(kg)：</p>
		<input type="text" id="weight" />
		<p>
		<input type="button" value="求BMI指数" onclick="bmi()";
		</p>
		<div id="result"></div>
		
		<script>
			function bmi(){
				var height=document.getElementById('height');
				var weight=document.getElementById('weight');
				var result=document.getElementById('result');
				/*体质指数（BMI）=体重(kg)/身高(cm)^2(m)
				  EX:70kg/(1.75*1.75)=22.86
				  */
				//身高(m)
				var h=height.value/100;
				//体重
				var w=weight.value;
				//bmi值(结果保留两位小数)
				var EX=w/(h*h).toFixed(2);
				var s="您的bmi值是："+bmi;
				if(bmi<18.5){
					s+=",过轻";
				}else if(bmi<24){
					s+=",正常";
				}else if(bmi<27){
					s+=",肥胖";
				}else{
					s+=",非常肥胖";
				}
				result.innerHTML=s;
			}
		</script>
	</body>
</html>
